// pages/service/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollHeight:0,
    screenWidth:0,
    srvCount: 0,
    srvAmount: 0,
    checkedSrv:[],
    csServices:[],
    srvDetails: [],
    details: {
      Guid: "00000000000000000000000000000000",
      HourCost: 0,
      Id: 0,
      Introduction: "",
      Name: "",
      Products: []
    },
    products: {
      CPTId: "",
      Model: "",
      Name: "",
      Price: 0,
      ProductName: ""
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          scrollHeight: res.windowHeight,
          screenWidth: res.windowWidth
        })
      },
    });
    wx.request({
      url: 'https://www.limecar.cn/WxApi/ServiceList',
      data:{ },
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        that.setData({
          csServices : res.data
        });
      }
    });
  },

  svrCheck: function (event) {
    let that = this;
    let amount = 0;
    let flag = false;
    let values = event.detail.value;
    let historyValues = that.data.checkedSrv.toString();
    let csSrv = that.data.csServices;
    for (let i = 0; i < values.length; i++) {
      for (let l = 0; l < csSrv.length; l++) {
        if (csSrv[l].Id == values[i]) {
          amount = amount + csSrv[l].Price;
          if (!flag && historyValues.indexOf(values[i]) < 0) {
            that.setData({
              details: csSrv[l]
            });
            break;
          }
        }
      }
    }
    that.setData({
      srvCount: values.length,
      srvAmount: amount,
      checkedSrv: values,
    })
  },

  CheckOut: function (){
    let that = this;
    if (that.data.checkedSrv == ""){
      wx.showToast({
        title: '您还未选择服务',
        icon: 'none',
        duration: 2200
      })
    }else{
      wx.navigateTo({
        url: './cart/checkout?checkedSrv=' + that.data.checkedSrv.toString()
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})